package cn.harry.cabinet.server.dto.operationlog

import cn.harry.cabinet.model.entity.OperationLog
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.Serializable

/**
 * 操作日志响应DTO
 */
@Serializable
@InternalSerializationApi
data class OperationLogResponse(
    val id: Long,
    val timestamp: Long,
    val operationType: String,
    val operationSubType: String?,
    val result: String,
    val description: String,
    val operatorId: Long?,
    val operatorEmployeeId: String?,
    val operatorName: String?,
    val targetId: Long?,
    val targetType: String?,
    val targetName: String?,
    val detailData: String?,
    val ipAddress: String?,
    val deviceInfo: String?,
    val errorMessage: String?,
    val errorCode: String?
) {
    companion object {
        /**
         * 从 OperationLog 实体转换为响应DTO
         */
        fun fromOperationLog(log: OperationLog): OperationLogResponse {
            return OperationLogResponse(
                id = log.id,
                timestamp = log.timestamp,
                operationType = log.operationType,
                operationSubType = log.operationSubType,
                result = log.result,
                description = log.description,
                operatorId = log.operatorId,
                operatorEmployeeId = log.operatorEmployeeId,
                operatorName = log.operatorName,
                targetId = log.targetId,
                targetType = log.targetType,
                targetName = log.targetName,
                detailData = log.detailData,
                ipAddress = log.ipAddress,
                deviceInfo = log.deviceInfo,
                errorMessage = log.errorMessage,
                errorCode = log.errorCode
            )
        }

        /**
         * 批量转换
         */
        fun fromOperationLogList(logs: List<OperationLog>): List<OperationLogResponse> {
            return logs.map { fromOperationLog(it) }
        }
    }
}
